import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Wode from '../views/wode.vue'
import Dindan from '../views/dindan.vue'
import Zhengxiang from '../views/zhengxiang.vue'
import Ads_choice from '../views/address_choice.vue'
import Foodcart from '../views/foodcart.vue'
import Page_search from '../views/page_search.vue'
import Shopinfo from '../views/shopinfo.vue'
import Allads from '../views/alladdress.vue'
import Store from '../store/index.js'


// import Shopshow from '../views/Homecontent/shopshow/shopshow.vue'

Vue.use(VueRouter)

// 路由中重复点击路由导致报错解决方案
// 路由冗余报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
    return originalPush.call(this, location).catch(err => err);
};

const routes = [{
        path: '/shouye',
        name: 'Home',
        component: Home,

    },
    {
        path: '/wode',
        name: 'Wode',
        component: Wode
    },

    {
        path: '/alladdress',
        name: 'Allads',
        component: Allads
    },
    {
        path: '/shopinfo',
        name: 'Shopinfo',
        component: Shopinfo
    },
    {
        path: '/dindan/:canshu1',
        name: 'Dindan',
        component: Dindan
    },
    {
        path: '/zhengxiang',
        name: 'Zhengxiang',
        component: Zhengxiang
    },
    {
        path: '/page_search',
        name: 'Page_search',
        component: Page_search
    },
    {
        path: '/address_choice',
        name: 'Ads_choice',
        component: Ads_choice
    },

    {
        path: '/foodcart',
        name: 'Foodcart',
        component: Foodcart,

    }, {
        path: '/login',
        name: 'Login',
        component: () =>
            import ('../views/login.vue')

    },
    {
        path: '/erlou',
        name: 'Erlou',
        component: () =>
            import ('../views/Homecontent/erlou.vue')

    },
    {
        path: '/register',
        name: 'Register',
        component: () =>
            import ('../views/register.vue')

    },
    {
        path: '/',
        redirect: "/shouye"
    },

]

const router = new VueRouter({
    mode: 'hash',
    base: process.env.BASE_URL,
    routes
})
router.beforeEach((to, from, next) => {


        if (to.path == "/foodcart" && Store.state.userid == -1) {
            router.push('/login')
        } else {
            next()
        }

    })
    //    // 路由独享守卫
    //    beforeEnter(to, from, next) {
    //     console.log(to);
    //     console.log(from);
    //     // 进行一些是否登录的判断判断成功让她进入  不成功不能进
    //     if (Store.state.username !== "") {
    //         next();
    //     } else {
    //         next({ name: "Login" })
    //     }


// }

export default router